<%@ page contentType="text/html;charset=UTF-8" %>

<!DOCTYPE html>
<html>
<head>
	<title>数据元素列表管理</title>
     <%@ include file="/common/meta.jsp" %>
	<%@ include file="/common/import.jsp" %>
	
	<script type="text/javascript">
	
		var sortId='${sortId}';
		$(function(){
			$('#metadataList').datagrid({
				//title:'数据元素列表',
				iconCls:'icon-ok',
				url:'${ctx}/info/metadata/metadata!data.action?sortId='+sortId,
				nowrap: false,
				striped: true,
				collapsible:false,	
				pagination:true,			
				fitColumns: true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pageList:[10,15,20,30],
				idField:'metadataId',
				columns:[[
					{field:'sortId',title:'所在分类',width:80},
					{field:'dataFullName',title:'全称',width:120},
					{field:'dataShortName',title:'字段名',width:100},
					{field:'dataAttr',title:'属性名',width:100},
					{field:'dataType',title:'数据类型',width:60,
						formatter:function(value){
							if(value=="1"){
							    return "整型";
							}else if(value=="2"){
							    return "长整型";
							}else if(value=="3"){
								return "小数";
							}else if(value=="4"){
								return "字节";
							}else if(value=="5"){
								return "字符";
							}else if(value=="6"){
								return "日期";
							}
						}
					},
					{field:'dataLength',title:'数据长度',width:80},
					{field:'dataRestrict',title:'数据约束',width:60,
						formatter:function(value){
							if(value=="1"){
							    return "主键";
							}else if(value=="2"){
							    return "非空";
							}else if(value=="3"){
								return "可空";
							}
						}
					}		
				]],				
				toolbar:[					
		          {		        	  
		              	text:'增加',
			              iconCls:'icon-add',
			              handler:function(){saveMetadata();}
		        	  
		          },'-',
		          {
		              text:'删除',
		              iconCls:'icon-cut',
		              handler:function(){deleteMetadata();}		             
		          },'-',
		          {
		              text:'修改',
		              iconCls:'icon-edit',
		              handler:function(){editMetadata();}
		          },
		          '-',
		           {
		              text:'刷新',
		              iconCls:'icon-reload',
		              handler:function(){
		                  reload();
		             }
		          }
		        ],
				onDblClickRow:function(row){
					editMetadata();
				}
			});
		});	
		
		// 增加模块
		function saveMetadata(){
			$('#unitAddFrame').html('');						
			var url = '${ctx}/info/metadata/add.action?sortId='+sortId;
			$('#unitAddFrame').attr("src",url);
			$('#unitAddWin').window('open');			
		}
			
		// 修改模块	
		function editMetadata(){
			$('#unitAddFrame').html('');
			var node = getSelected();
			if(node){
				var unitId = node.metadataId;
				var url = '${ctx}/info/metadata/add.action?id='+unitId;
				$('#unitAddFrame').attr("src",url);
				$('#unitAddWin').window('open');
			}
		}
		
		// 删除模块
		function deleteMetadata(){					
			var node = getSelected();	
			if(node){
		    	$.messager.confirm('确认','您确定要删除:<font color=red>'+node.dataFullName+' </font>？',function(r){
		        	if(r){
						$.ajax({
							type: "post",
							url: "${ctx}/info/metadata/del.action?id="+node.metadataId+"&sortId="+node.sortId,
							success: function(data, textStatus){
								var result = jQuery.parseJSON(data);
							    if(result.flag=='T'){									
									$.messager.alert('结果', '操作成功', 'info',function(){
									var rowIndex = $('#metadataList').datagrid('getRowIndex',node);								
									$('#metadataList').datagrid('deleteRow', rowIndex);
									});
								}else{
									$.messager.alert('提交结果', "操作失败："+result.msg, 'error');
								}			
							}
						});
		          	}
		       	});		             		
		    }	
		}
		
		// 判断修改、删除前是否选中记录
		function getSelected(){
			var selected = $('#metadataList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		// 刷新列表
		function reload(){
			$('#metadataList').datagrid('reload');
		}
		
		// 关闭窗口
		function closeAdd(){
			$('#unitAddWin').window('close');
		}
		$('#unitAddWin').bind("close", reload);	
	</script>
</head>

<body>
	
	<table id="metadataList"></table>
	
	<!-- 查询窗口 -->
	<div id="unitAddWin" class="easyui-window" title="添加数据元素" style="padding:5px;width: 500px;height:350px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   	 <iframe scrolling="yes" frameborder="0"  id="unitAddFrame" height="99%" width="100%" scrolling="No" frameborder="0" ></iframe>
    </div>
    
</body>
</html>